<?php
class NewproductImagesController extends AppController {

	var $name = 'NewproductImages';

	function admin_index() {
		$this->NewproductImage->recursive = 0;
		$this->set('newproductImages', $this->paginate());
	}

	function admin_view($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid newproduct image', true));
			$this->redirect(array('action' => 'index'));
		}
		$this->set('newproductImage', $this->NewproductImage->read(null, $id));
	}

	function admin_add() {
		if (!empty($this->data)) {
			$this->NewproductImage->create();
			if ($this->NewproductImage->save($this->data)) {
				$this->Session->setFlash(__('The newproduct image has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The newproduct image could not be saved. Please, try again.', true));
			}
		}
		$newproducts = $this->NewproductImage->Newproduct->find('list');
		$this->set(compact('newproducts'));
	}

	function admin_edit($id = null) {
		if (!$id && empty($this->data)) {
			$this->Session->setFlash(__('Invalid newproduct image', true));
			$this->redirect(array('action' => 'index'));
		}
		if (!empty($this->data)) {
			if ($this->NewproductImage->save($this->data)) {
				$this->Session->setFlash(__('The newproduct image has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The newproduct image could not be saved. Please, try again.', true));
			}
		}
		if (empty($this->data)) {
			$this->data = $this->NewproductImage->read(null, $id);
		}
		$newproducts = $this->NewproductImage->Newproduct->find('list');
		$this->set(compact('newproducts'));
	}

	function admin_delete($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid id for newproduct image', true));
			$this->redirect(array('action'=>'index'));
		}
		if ($this->NewproductImage->delete($id)) {
			$this->Session->setFlash(__('Newproduct image deleted', true));
			$this->redirect(array('action'=>'index'));
		}
		$this->Session->setFlash(__('Newproduct image was not deleted', true));
		$this->redirect(array('action' => 'index'));
	}
	
	function admin_ajaxdelete($id = null) {
		$this->layout = null;
		if (!$id) {
			$this->Session->setFlash(__('Invalid id for product image', true));
			//$this->redirect(array('action'=>'index'));
			$result = "false";
			$this->set(compact('result'));
			return;
		}
		if ($this->NewproductImage->delete($id)) {
			$this->Session->setFlash(__('Product image deleted', true));
			//$this->redirect(array('action'=>'index'));
			$result = "true";
			$this->set(compact('result'));
			return;
		}
		$this->Session->setFlash(__('Product image was not deleted', true));
		//$this->redirect(array('action' => 'index'));
		$result = "false";
		$this->set(compact('result'));
	}
}
